package com.heima.admin.controller.v1;


import com.heima.admin.service.ChannelService;
import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.admin.pojos.AdChannel;
import com.heima.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@Api(tags = "频道管理API",value = "频道管理API")
@RestController
@RequestMapping("/api/v1/channel")
public class AdChannelController {


    /**
     *
     */
    @Autowired
    ChannelService channelService;


    @ApiOperation("根据名字模糊分页查询")
    @PostMapping("list")
    public ResponseResult list(@RequestBody ChannelDto dto){
        return channelService.findByNameAndPage(dto);
    }

    @ApiOperation(value = "添加频道",notes = "频道名称不能为空,不能重复")
    @PostMapping("save")
    public ResponseResult save(@RequestBody AdChannel channel){
        return channelService.insert(channel);
    }


    @ApiOperation(value = "修改频道",notes = "修改和启用禁用的公用方法")
    @PostMapping("update")
    public ResponseResult update(@RequestBody AdChannel channel){
        return channelService.update(channel);
    }


    @ApiOperation(value = "删除频道",notes = "如果频道有效则不能删除")
    @GetMapping("del/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        return channelService.delete(id);
    }

    @ApiOperation("查询全部频道")
    @GetMapping("/channels")
    public ResponseResult findAll() {
        List<AdChannel> list = channelService.list();
        return ResponseResult.okResult(list);
    }

}
